package model.analyzer;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.util.NoSuchElementException;
import java.util.Scanner;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import model.core.graph.WordToken;

import DAO.IWordDAO;
import DAO.mysql.MySQLDAO;

public class WordDumper {
	
	public static void main(String[] args) throws FileNotFoundException {
		dumpWordList();
	}
	
	public static void dumpWordList() throws FileNotFoundException {
		MySQLDAO sqlDAO = new MySQLDAO();
		Pattern p = Pattern.compile("[A-Z]*[a-z]+");
		File f = new File("./wordList/words.english");
		System.out.println(f.exists());
		Scanner scanner = new Scanner(
				new FileInputStream(new File("./wordList/words.english")));
		//int count = 100;
		String word = null;
		IWordDAO wrd = sqlDAO.getWordDAO();
		try {
			while((word = scanner.nextLine()) != null) {//count > 0) {
				//--count;
				Matcher mtcher = p.matcher(word);
				if(mtcher.matches()) {
					wrd.declareToken(new WordToken(word));
				}
			}
		} catch (NoSuchElementException e) {
			//over
		}
	}
}
